/**
 * Author:  LiShibin.
 * Date:    2017/7/5 0005.
 * File：   .
 */
import config from '../config'
import BaseNative from './BaseNative'
import PcNative from './PcNative'
import PhoneNative from './PhoneNative'
import WeixinNative from './WeixinNative'
import * as utils from '../utils'
let instance = null

function creatNative() {
  let native = new BaseNative()
  let deviceType = utils.getDeviceType() // 获取浏览器类型
  if (config.pcTest) { // 配置强制开启pc浏览器测试
    deviceType = 'Windows'
  }
  switch (deviceType) {
    case 'Windows':
      native = new PcNative()
      break
    case 'Android':
    case 'iPhone':
    case 'APICloud':
      native = new PhoneNative()
      break
    case 'wx-iPhone':
    case 'wx-Android':
      native = new WeixinNative()
      break
  }
  return native
}
function getInstance() {
  if (!instance) {
    instance = creatNative()
  }
  return instance
}

export {getInstance}
